<?php
class Login extends Controller{
	
	function login(){
		parent::Controller();
		$this->load->model('login_m');
	}
	
	function index(){
		if ($this->session->userdata('status') == TRUE){
			redirect('home');
		} else {
			$this->load->view('login/login_v');
		}
	}
	
	function plogin(){
		$passdb = $this->login_m->cek_login();
		if ($passdb == TRUE){
			$hasil = $this->login_m->get_data($this->input->post('user_id'));
			foreach ($hasil as $itu){
				$id_user = $itu->ID_CABANG;
				$id_pengguna = $itu->ID_PENGGUNA;
				$nama = $itu->NAMA_C;
			}
			$sesdata = array('user_id' => $id_user,
							'status' => 4,
							'nama' => $nama,
							'induk' =>$id_pengguna,
							'login' => TRUE);
			$this->session->set_userdata($sesdata);
			redirect('home');
		}
		else{
			$this->session->set_flashdata('pesan','Password yang anda masukkan salah, silahkan masukkan lagi');
			$this->load->view('login/login_v');
		}
	}
}
?>